﻿/*
=======================================================
    Regulator【监管部门】
=======================================================
*/

namespace Services
{
    public interface IRegulatorLogic : ILogic<RegulatorModel, RegulatorFilterModel>
    {
        int UpdateIsDelete(bool flag, params int[] ids);
    }


    public class RegulatorLogic : BaseLogic<RegulatorModel, RegulatorFilterModel, Regulator, IRegulatorRepository, IRegulatorMapping, IRegulatorService>, IRegulatorLogic
    {
        private readonly IGroupInfoRepository _IGroupInfoRepository;
        private readonly ICreateCode _ICreateCode;

        public RegulatorLogic(ICurrentUser currentUser, IRegulatorRepository repository, IRegulatorMapping mapping, IRegulatorService service, IGroupInfoRepository iGroupInfoRepository, ICreateCode iCreateCode)
            : base(currentUser, repository, mapping, service)
        {
            _IGroupInfoRepository = iGroupInfoRepository;
            _ICreateCode = iCreateCode;
        }

        #region 启用/禁用  UpdateIsDelete
        public int UpdateIsDelete(bool flag, params int[] ids)
        {
            return _repository.UpdateIsDelete(flag, ids);
        }
        #endregion

        #region Insert
        public override RegulatorModel Insert(RegulatorModel model)
        {
            if (model.Code.IsEmpty())
            {
                model.Code = _ICreateCode.GetRegulatorCode();
            }

            if (_ICreateCode.GroupInfoOrRegulatorCodeIsExists(model.Code))
            {
                throw new CustomException("编号已经存在，系统要求集团与监管部门的编号要唯一！");
            }

            return base.Insert(model);
        }
        #endregion
    }
}
